import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'dart:convert' as convert;

import 'package:flutter/material.dart';
import 'package:graduation_project/myMessage/myMessageList.dart';

class myMessage extends StatefulWidget {
  const myMessage({Key key}) : super(key: key);

  @override
  State<myMessage> createState() => _myMessageState();
}

class _myMessageState extends State<myMessage> {
  Future _future;
  List cartoonList;
  _getinformation() async {
    Response response;
    var dio = Dio();
    dio.options.responseType = ResponseType.plain;
    response = await dio.get('http://119.91.231.198:3033/useMsg');
    var res = convert.jsonDecode(response.toString());
    Response response0;
    response0 = await dio.get(
        'http://119.91.231.198:3033/getBookrackValue?bookrack_id=1'.toString());
    var res0 = convert.jsonDecode(response0.toString());
    cartoonList = res0['valueList'];
  }

  @override
  void initState() {
    _future = _getinformation();
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: _future,
        builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            print(cartoonList);
            return NestedScrollView(
              headerSliverBuilder:
                  (BuildContext context, bool innerBoxIsScrolled) {
                return <Widget>[
                  SliverAppBar(
                    iconTheme: IconThemeData(color: Colors.black87),
                    automaticallyImplyLeading: true,
                    backgroundColor: Colors.white,
                    expandedHeight: 200.0,
                    pinned: false,
                    floating: true,
                    snap: false,
                    flexibleSpace: FlexibleSpaceBar(
                      //可以展开区域，通常是一个FlexibleSpaceBar
                      background: Image(
                        image: NetworkImage(
                            'https://img0.baidu.com/it/u=1861461045,4173684878&fm=253&fmt=auto&app=120&f=JPEG?w=1584&h=800'),
                      ),
                    ),
                  )
                ];
              },
              body: ListView.builder(
                  // controller: _scrollController,
                  itemCount: 1,
                  itemBuilder: (BuildContext context, int index) {
                    return Container(
                      child: Column(children: [
                        Row(
                          children: [
                            Transform.translate(
                              offset: Offset(0, -30),
                              child: Container(
                                margin: EdgeInsets.only(left: 20),
                                width: 100,
                                height: 100,
                                decoration: new BoxDecoration(
                                  // color: Colors.red,
                                  // 设置四周圆角，角度
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(100.0)),
                                ),
                                clipBehavior: Clip.hardEdge,
                                child: Image(
                                  image: NetworkImage(
                                      'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202005%2F03%2F20200503193405_QavAd.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651841860&t=ef1ab5509bcf14053ca92ec2dbb36bb5'),
                                ),
                              ),
                            ),
                            Container(
                              height: 100,
                              margin: EdgeInsets.only(left: 30),
                              child: Text(
                                '我心明浪子',
                                style: TextStyle(fontSize: 24),
                              ),
                            ),
                          ],
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 20, bottom: 20),
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '追番列表',
                            style: TextStyle(fontSize: 26),
                          ),
                        ),
                        myMessageList(
                          cartoon_list: cartoonList,
                        ),
                        SizedBox(
                          height: 50,
                        )
                      ]),
                    );
                  }),
            );
          } else {
            return Container();
          }
        });
  }
}
